<?php
namespace App\Repositories;

use App\Models\Role;
use Illuminate\Support\Facades\Input;

class RoleRepository
{
    
    public function rolesJson(){
        $collection = Role::select(['id','display_name'])->get();
        return $collection->toJson();
    }
    /**
     * Get permissions list with parent info.
     *
     * @return collection
     */
    public function roles()
    {
        $start   = Input::get('start', 0);
        $length  = Input::get('length', 30);
        $page    = $start / $length + 1;
        
        $collection = Role::select('*')
            ->display_name()
            ->name()
            ->orderBy('id', 'ASC')
            ->paginate($length, ['*'], 'page', $page);

        return $collection;
    }

    public function store(array $input)
    {
        $model = Role::create($input);

        if (empty($model->id)) {
            return false;
        }
        return true;
    }

    public function delete($role, $id)
    {
        $role->permissions()->detach();
        return Role::where('id', $id)->delete();
    }

    public function update(array $input, $role)
    {
        $result = $role->update($input);
        return $result;
    }
}